package coreAlgorithm;


public class Bit {
	private int value;

	public Bit(int value) {
		super();
		this.setValue(value);
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		if(value != 0 && value != 1) throw new IllegalArgumentException("Bits must be 0 or 1, but was " + value);
		this.value = value;
	}
	
	public boolean equals(Bit cmpBit) {
		return (this.getValue() == cmpBit.getValue());
	}
	
	public boolean equals(Object cmpObj) {
		if(cmpObj instanceof Bit) {
			return equals((Bit) cmpObj);
		} else { return false;}
	}
	
	public String toString() {
		return String.valueOf(this.getValue());
	}
	
	@Override
	public int hashCode() {
		return value;
	};
}
